package com.qiezi.common.exception;

import java.util.ArrayList;
import java.util.List;

public class MessageException extends Exception {
    private List<String> messageList;

    public MessageException() {
        messageList = new ArrayList<>();
    }

    public MessageException(String message) {
        messageList = new ArrayList<>();
        messageList.add(message);
    }

    public MessageException(List<String> messageList) {
        this.messageList = messageList;
    }

    public void addMessage(String message) {
        messageList.add(message);
    }

    public List<String> getMessageList() {
        return this.messageList;
    }

    @Override
    public String getMessage() {
        if(messageList != null && messageList.size() > 0) {
            StringBuffer sb = new StringBuffer();
            for(String messsage : messageList) {
                sb.append(messsage + ";");
            }
            return sb.toString();
        }
        return null;
    }
}
